package com.example.question.tree.tree3;

import com.example.question.tree.tree1.TreeNode;

/**
 * @Date 2023-07-14
 * @Author Jonathan
 */
public class Code08_108 {
    public static void main(String[] args) {

    }


    public TreeNode sortedArrayToBST(int[] nums) {
        return transfer(nums, 0, nums.length);
    }

    private TreeNode transfer(int[] nums, int left, int right) {
        if (left > right) {
            return null;
        }
        int mid = (left + right) / 2;
        TreeNode treeNode = new TreeNode(nums[mid]);
        treeNode.left = transfer(nums, left, mid - 1);
        treeNode.right = transfer(nums, mid + 1, right);
        return treeNode;
    }

}
